﻿using MvCameraControl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace OCR.SystemThread
{
    class CameraReceiveRealTimeThread
    {
        public static bool CameraReceiveRealTime_Flowrec = false;
        public static Thread CameraReceiveRealTimeFlow_Thread = null;
        public static int iCameraReceiveRealTime_Step = 0;

        public static bool CameraReceiveRealTime_Stop = false;
        public static void CameraReceiveRealTime_Thread()
        {
            CameraReceiveRealTime_Flowrec = true;
            CameraReceiveRealTimeFlow_Thread = new Thread(CameraReceiveRealTimeFlowThread);
            CameraReceiveRealTimeFlow_Thread.IsBackground = true;
            CameraReceiveRealTimeFlow_Thread.Start();
        }

        private static void CameraReceiveRealTimeFlowThread(object obj)
        {
            while (CameraReceiveRealTime_Flowrec)
            {
                switch (iCameraReceiveRealTime_Step)
                {
                    case 0:
                        //AlgorithmModule.ImageHandleV2_Refresh(Application.StartupPath + "\\TemplateInput\\Refresh.bmp");

                        break;
                    case 5:
                        //AlgorithmModule.ImageHandleV2_Refresh(Application.StartupPath + "\\TemplateInput\\Refresh.bmp");

                        if (!CameraReceiveThread.isGrabbing)
                        {
                            iCameraReceiveRealTime_Step = 0;
                            return;
                        }

                        //int result = CameraReceiveThread.device.Parameters.SetCommandValue("TriggerSoftware");
                        //if (result != MvError.MV_OK)
                        //{
                        //    CameraReceiveThread.ShowErrorMsg("Trigger Software Fail!", result);
                        //    iCameraReceiveRealTime_Step = 0;
                        //}


                        IOThread_Run.DO_Trigger_olng(0, 1);
                        //Console.WriteLine("开DO");
                        
                        Thread.Sleep(50);
                        
                        IOThread_Run.DO_Trigger_olng(0, 0);
                        //Console.WriteLine("关DO");
                        
                        Thread.Sleep(100);

                        break;
                }
                Thread.Sleep(1);
            }
        }
    }
}
